﻿Public Class Logger

    Public Shared Sub MsgLog(ByVal Msg As String)
        'for more messages
        Using sw As New System.IO.StreamWriter(My.Application.Info.DirectoryPath & "\log.txt", True)
            sw.WriteLine("Msg at " & Now() & " - " & Msg)
        End Using

        If My.Settings.bDisplayErrors Then
            Dim mbrResult As MsgBoxResult = MsgBox(Msg, MsgBoxStyle.OkOnly, "Logged Message")
        End If
    End Sub

    Public Overloads Shared Sub ErrorLog(ByVal ErrMsg As String)
        'for errors
        Using sw As New System.IO.StreamWriter(My.Application.Info.DirectoryPath & "\log.txt", True)
            sw.WriteLine("Error at " & Now() & " - " & ErrMsg)
        End Using

        If My.Settings.bDisplayErrors Then
            Dim mbrResult As MsgBoxResult = MsgBox(ErrMsg, MsgBoxStyle.OkCancel, "Error")
            If mbrResult = MsgBoxResult.Cancel Then End
        End If

    End Sub

    Public Overloads Shared Sub ErrorLog(ByVal Excp As Exception, ByVal Location As String)
        'for errors using exception as the base
        Dim sErrMsg As String

        If Excp.InnerException Is Nothing Then
            sErrMsg = "Error in " & Location & ": " & Excp.ToString & "-" & Excp.Message
        Else
            sErrMsg = "Error in " & Location & ": " & Excp.ToString & "-" & Excp.Message & "-" & Excp.InnerException.ToString
        End If

        Using sw As New System.IO.StreamWriter(My.Application.Info.DirectoryPath & "\log.txt", True)
            sw.WriteLine("Error at " & Now() & " - " & sErrMsg)
        End Using

        If My.Settings.bDisplayErrors Then
            Dim mbrResult As MsgBoxResult = MsgBox(sErrMsg, MsgBoxStyle.OkCancel, "Error")
            If mbrResult = MsgBoxResult.Cancel Then End
        End If
    End Sub


End Class
